/*
 *	Copyright © 2013 Changsha Shishuo Network Technology Co., Ltd. All rights reserved.
 *	长沙市师说网络科技有限公司 版权所有
 *	http://www.shishuo.com
 */


package com.hlingsoft.kkh.action;

import com.hlingsoft.kkh.dao.MessageDao;
import com.hlingsoft.kkh.entity.AppUserMessage;
import com.hlingsoft.kkh.entity.MerchantMessage;
import com.hlingsoft.kkh.entity.SystemMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 消息
 *
 * @author Herbert
 */


@Controller
@RequestMapping("/message")
public class MessageAction extends BaseAction {

    @Autowired
    private MessageDao messageDao;

    private static final int rows = 999;

    /**
     * 用户消息
     * @param appUserId
     * @param request
     * @return
     */
    @RequestMapping(value = "/appList.json", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> appUserList(
            @RequestParam(value = "appUserId") long appUserId,
            HttpServletRequest request) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        try {
            List<SystemMessage> systemMessage = messageDao.getUnReadUserSystemMessageList(0,rows); //发给所有用户
            List<AppUserMessage> messageList = messageDao.getUnReadMessageListByUserId(appUserId, 0, rows);
            resultMap.put("systemMessage", systemMessage);
            resultMap.put("messageList",messageList);
            resultMap.put("result", true);

        } catch (Exception e) {
            e.printStackTrace();
            resultMap.put("result", false);
        }
        return resultMap;
    }

    /**
     * 商户消息
     * @param merchantId
     * @param request
     * @return
     */
    @RequestMapping(value = "/merchantList.json", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> merchantList(
            @RequestParam(value = "merchantId") long merchantId,
            HttpServletRequest request) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        try {
            List<SystemMessage> systemMessage = messageDao.getUnReadMerchantSystemMessageList(0, rows);
            List<MerchantMessage> messageList = messageDao.getUnReadMessageListByMerchantId(merchantId, 0, rows);

            resultMap.put("systemMessage",systemMessage);
            resultMap.put("messageList",messageList);
            resultMap.put("result", true);

        } catch (Exception e) {
            e.printStackTrace();
            resultMap.put("result", false);
        }
        return resultMap;
    }

}
